package com.xindaoapp.henghua.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class CustomViewPager extends ViewPager {

	private View[] mViews;

	public CustomViewPager(Context context) {
		super(context);
	}

	public CustomViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void initTabs(View[] views, int tabIndex) {
		this.mViews = views;
		initListener();
		selected(tabIndex);
	}

	private void initListener() {
		for (int i = 0; i < mViews.length; i++) {
			final int temp = i;
			mViews[i].setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					setCurrentItem(temp);
					selected(temp);
				}
			});
		}
	}

	public void selected(int position) {
		for (int i = 0; i < mViews.length; i++) {
			if (position == i) {
				mViews[i].setSelected(true);
			} else {
				mViews[i].setSelected(false);
			}
		}
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent arg0) {
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent arg0) {
		return false;
	}

}
